package org.example.rubbish.mapper;


import org.apache.ibatis.annotations.*;
import org.example.rubbish.entity.ExceptionReport;

import java.util.Date;
import java.util.List;

@Mapper
public interface ExceptionReportMapper {
    @Insert("INSERT INTO exception_report(station_id, reporter_id, type, description, image_url, video_url, status) " +
            "VALUES(#{stationId}, #{reporterId}, #{type}, #{description}, #{imageUrl}, #{videoUrl}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(ExceptionReport report);

    @Update("UPDATE exception_report SET status=#{status}, audit_time=NOW(), auditor_id=#{auditorId}, " +
            "audit_result=#{auditResult} WHERE id=#{id}")
    void audit(ExceptionReport report);

    @Select("SELECT * FROM exception_report WHERE id=#{id}")
    ExceptionReport selectById(Long id);

    @Select("SELECT * FROM exception_report WHERE status=#{status}")
    List<ExceptionReport> selectByStatus(Integer status);

    @Select("SELECT * FROM exception_report WHERE create_time BETWEEN #{startTime} AND #{endTime}")
    List<ExceptionReport> selectByTimeRange(Date startTime, Date endTime);

    @Select("SELECT * FROM exception_report WHERE station_id=#{stationId}")
    List<ExceptionReport> selectByStationId(Long stationId);
}
